<?php 

class App_Model_DbTable_Article_Attachment_Image extends Ext_Db_Table  
{  
    protected $_name = 'article_attachment_image';
    
    private static $_imageRow = array();
    
    public function getRowByArticleId($articleId)
    {
        if(!$articleId)
        {
            return "";
        }
        
        if(isset(self::$_imageRow['articleId'][$articleId]))
        {
            return self::$_imageRow['articleId'][$articleId];
        }
        
        $db = $this->getAdapter();
        $safe = $db->quoteInto(" articleId = ? ", $articleId);
        $row = $this->fetchRow($safe);
        if (!$row) {
            return "";
        }
        $_imageRow = $row->toArray();
        
        self::$_imageRow['articleId'][$articleId] = $_imageRow;
        
        return $_imageRow;
    }
    
    public function addNew($inputArray)
    {
        $sql_data_array = array();
        if(array_key_exists('articleId', $inputArray)) $sql_data_array['articleId'] = $inputArray['articleId'];
        if(array_key_exists('ids', $inputArray)) $sql_data_array['ids'] = $inputArray['ids'];
        
        try {
            $rows_affected = $this->insert($sql_data_array);
        }catch (Exception $e){
            trigger_error($e->getMessage(), E_USER_WARNING);
        }
        
        return "";
    }
    
    public function addOld($inputArray, $articleId)
    {
        $articleId = intval($articleId);
        
        $sql_data_array = array();
        if(array_key_exists('ids', $inputArray)) $sql_data_array['ids'] = $inputArray['ids'];
                
        try {
            $db = $this->getAdapter();
            $where = $db->quoteInto(" articleId = ? ", $articleId);
            $rows_affected = $this->update($sql_data_array, $where);
        }catch (Exception $e){
            trigger_error($e->getMessage(), E_USER_WARNING);
        }
        
        return "";
    }
}